#!/usr/bin/env python
# coding: utf-8

from pyDes  import CBC, PAD_PKCS5,des
import base64
from datetime import datetime

KEY="KenGbibi"
IV = "\0\0\0\0\0\0\0\0"

def encrypt_str(message):
    data = unicode(message, "UTF-8")
    encode_data = data.encode("UTF-8")
    k = des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
    return base64.encodestring(k.encrypt(encode_data))

def decrypt_str(message):
    deconde_data = base64.decodestring(message)
    k = des(KEY, CBC, IV, pad=None, padmode=PAD_PKCS5)
    return k.decrypt(deconde_data)


if __name__ == "__main__":
    data = {
            #"user_agent":"Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; X909T Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
            #"datetime":str(datetime.now()),
            "user_id":213071771,
            "token":6568068
            }
    print "datetime" in data and "user_id" in data
    pass
    
    print str(data)
    d = encrypt_str(str(data))
    print d
    print decrypt_str(d)
    print eval(decrypt_str("bRF8z17NL5qpiojUm8/Jr5bodFKpmb2nwGD6kuFlfkQ5c65L7+mzpg=="))['token']
    
    